//
//  HMSignUpStrongCourseVC.m
//  HMSignUpStrongCourse
//
//  Created by 陈辉明 on 2017/11/25.
//  Copyright © 2017年 goldwin. All rights reserved.
//

#import "HMSignUpStrongCourseVC.h"
#import "HMSignUpStrongCourseCell.h"
#import "HMSignUpStrongCourseModel.h"
#import "ZYAddStrongCouseDetailController.h"
//#import "ZYYSViewController.h"
@interface HMSignUpStrongCourseVC () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong) NSMutableArray <HMSignUpStrongCourseModel *>*dataArray;
@property (weak, nonatomic) IBOutlet UILabel *headTitleLabel;

@end

@implementation HMSignUpStrongCourseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTableView];
    [self setNetWork];
    self.title = @"课程要素";
}

- (void) setTableView {
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"HMSignUpStrongCourseCell" bundle:nil] forCellReuseIdentifier:@"HMSignUpStrongCourseCellId"];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 60;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.headTitleLabel.text = [NSString stringWithFormat:@"课程名称: %@(加强课)",self.titleName];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HMSignUpStrongCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HMSignUpStrongCourseCellId" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataArray[indexPath.section];
    

    cell.seeMoreBlock = ^(HMSignUpStrongCourseModel *blcokModel) {
        
        ZYAddStrongCouseDetailController *VC = [[ZYAddStrongCouseDetailController alloc] init];
        VC.ID = blcokModel.Id;
        [self.navigationController pushViewController:VC animated:YES];
//        ZYYSViewController *vc = [ZYYSViewController new];
//
//        vc.browseType = BrowseTypeCourse;
//        vc.courseID =  [NSString stringWithFormat:@"%@",blcokModel.Id];
//        vc.subject =  [NSString stringWithFormat:@"%@",blcokModel.name];
//
//        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//        NSString *longitude = [defaults objectForKey:@"longitude"];
//        NSString *latitude = [defaults objectForKey:@"latitude"];
//
//        vc.longitude = [NSString stringWithFormat:@"%@",longitude];
//        vc.latitude = [NSString stringWithFormat:@"%@",latitude];
//
//        vc.isStrongCouseUp = YES;
//        [weakSelf.navigationController pushViewController:vc animated:YES];
        
    };
    return  cell;
}

-(NSMutableArray<HMSignUpStrongCourseModel *> *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}


- (void)setNetWork{
    
     //http://192.168.0.113:8080/StarShine/ws/trainLesson.do?action=enrollReinforce&lessonId=772
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    NSString *url = [NSString stringWithFormat:@"trainLesson.do?action=enrollReinforce&lessonId=%@",self.courseID];

    
    [NetManager Get:LLBaseURLs(url) Auth:YES Params:nil Success:^(id Obj) {
        [SVProgressHUD dismiss];
        if ([[Obj valueForKey:@"code"] integerValue] == 1000) {
            [self.dataArray removeAllObjects];
            NSArray *tArray = [Obj valueForKey:@"t"];
            for (NSDictionary *dict in tArray) {
                HMSignUpStrongCourseModel *model =  [HMSignUpStrongCourseModel HMSignUpStrongCourseModelWithDict:dict];
                [self.dataArray addObject:model];
            }
             [self.tableView reloadData];
        }
            
        
        
    } Fail:^(NSError *Error) {
        [SVProgressHUD dismiss];
//        [SVProgressHUD showErrorWithStatus:LLNetWorkError];
    }];
   

    
}




@end
